import 'package:flutter/cupertino.dart';
import 'package:pkg_obz/core/global.dart';

// 路由不用传context,但是必须在程序入口配置navigatorKey: Global.globalKey
// MaterialApp(
//    navigatorKey: Global.globalKey,
// )
class ZRouter {
  ///路由跳转,入栈
  static goTo(Widget page) {
    Navigator.push(
      Global.globalKey.currentState!.context,
      CupertinoPageRoute(builder: (context) => page),
    );
  }

  ///关闭页面，弹框
  static goBack() => Navigator.pop(Global.globalKey.currentState!.context);

  ///路由跳转,替换
  static goToReplace(Widget page) async {
    Navigator.pushReplacement(
      Global.globalKey.currentState!.context,
      CupertinoPageRoute(builder: (context) => page),
    );
  }

  ///路由跳转,并清空栈内所有页面
  static goToReplaceAll(Widget page) async {
    Navigator.pushAndRemoveUntil(
      Global.globalKey.currentState!.context,
      CupertinoPageRoute(builder: (crx) => page),
      (route) => false,
    );
  }
}
